package com.example.leetcode.leetcode;


/**
 * @author haitao
 * 最长回文字符串，双指针算法
 */
public class Solution5 {

    public static String longestPalindrome(String s) {
        if (s==null|| "".equals(s)) {
            return null;
        }
        String result = "";

        for (int i = 0; i < s.length(); i++) {
            int left = i;
            int right = i;
            while (right < s.length() - 1 && s.charAt(right + 1) == s.charAt(right)){
                ++right;
            }

            while (left >= 0 && right < s.length()) {
                if (s.charAt(left) == s.charAt(right)) {
                    String temp = s.substring(left, right + 1);
                    result = temp.length() > result.length() ? temp : result;
                    left--;
                    right++;
                } else {
                    break;
                }
            }

        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(longestPalindrome("cbbd"));
    }
}
